import { AxiosPromise } from 'axios';

export type Action = {
  type: string;
  payload: any;
};
export interface IPayload<T> {
  type: string;
  payload?: AxiosPromise<T> | T;
  meta?: any;
}

export type IPayloadResult<T> = ((dispatch: any) => IPayload<T> | Promise<IPayload<T>>);

export type IGetAction<T> = (id: string | number) => IPayload<T> | ((dispatch: any) => IPayload<T>);

export type IGetListAction<T> = (
  params?:object,
  page?: number,
  pageSize?: number,
  sort?: string|string[]
) => IPayload<T> | ((dispatch: any) => IPayload<T>);

export type IPostAction<T> = (data?: T) => IPayload<T> | IPayloadResult<T>;

export type IPutAction<T> = (data?: T) => IPayload<T> | IPayloadResult<T>;

export type IDeleteAction<T> = (
  id?: string | number
) => IPayload<T> | ((dispatch: any) => IPayload<T>);

export type IAction<T> = (data?: T) => IPayload<T>;
